import axios from 'axios'
import qs from 'qs'
var root = process.env.API_ROOT;

axios.interceptors.request.use((config) => {
  //请求之前重新拼装url
  config.url = root + config.url;
  return config;
});
axios.defaults.withCredentials=true;

const commonMethods = {
    methods:{
        post:function(url,data,type){
          this.$store.commit('showLoading');
            return axios({
                method:'post',
                url: url,
                // emulateJSON: true,
                data: data,
                timeout: 50000
              }).then(
                (response) => {
                  this.$store.commit('hideLoading');
                  console.log(response);
                  return response;
                }
              ).catch(()=>{
                this.$store.commit('hideLoading');
                console.log('catch error',error);
                this.$toast.fail('Server Error');
              })
        },
        get:function(url){
          this.$store.commit('showLoading');
            return axios({
                method:'get',
                url: url,
                timeout: 50000,
              }).then(
                (response) => {
                  this.$store.commit('hideLoading');
                  console.log(response);
                 return response;
                }
              ).catch((error)=>{
                this.$store.commit('hideLoading');
                console.log('catch error',error)
                this.$toast.fail('Server Error');

              })
        },
        checkIsSsuccess:function(res){
          if(res.status=='200'&&res.data&&res.data.status=='00'){
            return true;
          }else{
            return false;
          }
        },checkEnv:function(){
          var NODE_ENV = process.env.NODE_ENV;
          var flag = NODE_ENV== 'development';
          return flag;
        },checkBrow(){
          if (/AlipayClient/.test(window.navigator.userAgent)) { 
            return true;
          } else {
             return false;
            
          }
        }
    }
}
export default commonMethods;